var _class, _temp;

import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text, RichText } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, partOf, subtime } from "../../utils/common";
import activity_detailStyleSheet from "./activity_detail_styles";
import banner_03 from '../../assets/img/banner_03.jpg';
var _styleSheet = activity_detailStyleSheet;
let Success = (_temp = _class = class Success extends Component {
  constructor(props) {
    super(props);
    this.state = {
      info: {},
      activity: []
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '活动详情' });
    let id = parseInt(this.$router.params.id);
    this.getActivitiesInfo(id);
    this.getPagedActivitiesInfo();
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  // 获取活动详情
  getActivitiesInfo(id) {
    let { PublicWelfareStore } = this.props.stores;
    PublicWelfareStore.getActivitiesInfo({
      formId: id,
      callback: res => {
        this.setState({ info: toJS(res) });
      }
    });
  }
  // 获取其他活动列表
  getPagedActivitiesInfo() {
    let { PublicWelfareStore } = this.props.stores;
    PublicWelfareStore.getPagedActivitiesInfo({
      pageIndex: 1,
      pageSize: 6,
      callback: res => {
        let resArr = toJS(res.items);
        // 去除该条信息
        resArr && resArr.map((item, index) => {
          if (item.id === parseInt(this.$router.params.id)) {
            resArr.splice(index, 1);
          }
        });
        this.setState({
          activity: resArr
        });
      }
    });
  }
  render() {
    let { activity, info } = this.state;
    console.log(info);
    console.log(activity);
    return <View style={_styleSheet["welfare-activity-detail"]}>
        <Image src={banner_03} style={_styleSheet["header-pic"]} />

        <View style={_styleSheet["activity-detail"]}>
          <View style={_styleSheet["list-title"]}>
            {info.title}
          </View>
          <View style={_styleSheet["list-info"]}>{subtime(info.creationTime)}</View>
        <View style={[_styleSheet["welfare-article"], _styleSheet["rich-text"]]}>
          <RichText nodes={info.content} />
        </View>
        </View>
        <View style={_styleSheet["interval"]} />
        {activity.length > 0 && <View>
           <View style={[_styleSheet["column-title"], _styleSheet["content-30"]]}>
              <Text style={_styleSheet["column-name"]}>其他慈善活动</Text>
           </View>
           <View style={_styleSheet["list-17"]}>
             {activity.map(item => {
            return <View key={item.id} onClick={this.handelRouter.bind(this, '/pages/public_welfare/activity_detail?id=' + item.id)} style={_styleSheet["list-17-item"]}>
                     <Image src={item.logoImg} style={_styleSheet["img"]} />
                     <View style={_styleSheet["info"]}>
                       <View style={_styleSheet["list-title"]}>{item.title}</View>
                       <View style={_styleSheet["list-desc"]}>{partOf(item.introduce, 50)}</View>
                     </View>
                   </View>;
          })}
           </View>
        </View>}
      </View>;
  }
}, _class.config = {
  navigationBarTitleText: '活动详情'
}, _temp);
Success = tslib_1.__decorate([inject("stores"), observer], Success);
export default Success;